package com.fy.tt.executor.node.word.verb;

import com.fy.tt.executor.environment.Environment;

import java.util.HashMap;
import java.util.Map;

import static com.fy.tt.utils.BandCore.doPostWithAccessToken;
import static com.fy.tt.utils.BandCore.getAccessToken;


public class Alarm extends Verb {
    public String text;
    private String address;
    private String method;
    private Map<String, String> params = new HashMap<>();

    public Alarm(String text) {
        this.text = text;
    }

    @Override
    public boolean run(String methodName) {
        boolean res = true;
        System.out.println("text:" + text);
        System.out.println("text:" + text);
        Object object = Environment.environment.get("Identifier");
        System.out.println(object.toString() + "发出警报");
//
//        address = "https://www.wetoband.com/tre/runTool?toolID=5300021468&gid=5300020935&bandID=5300020935";
        Map<String, String> alarmParams = new HashMap<>();
        alarmParams.put("param", "%7B%22action%22%3A%22doDefaultAlarm%22%7D");
        alarmParams.put("returnType", "value");
//
//        new HttpsUtils(address,method,params);

        String accessToken = null;
        try {
            accessToken = getAccessToken();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("accessToken:" + accessToken);
        String alarmUrl = "https://www.wetoband.com/tre/runTool?toolID=5300021468&gid=5300020935&bandID=5300020935";
        String Res = doPostWithAccessToken(alarmUrl, accessToken, alarmParams);
        System.out.println("Res:" + Res);

        //灯闪烁
        Map<String, String> lightParam = new HashMap<>();
        lightParam.put("gid", "5309707");
        lightParam.put("tp", "f6e8d3e6184e60de25a4ea551c904712032152986cec98b0c4e26411d856677eff35e17b03e92f54d1572d9e24940ca5a6d7cde689d247693a14e2c657c004751e19d03cb928fd3ef649226b85b2198f1bda0981fe902865eabe40fb0a57f3b2260b811fabfaec8e4511bfbe698cef1f07a66c3908fc0fd27b6cff67a23163cdae0b4fa462e06f541c2e8071fed6730a3145c3b214f3a67ea97f1558d013cbcfa1916d18297f7749900936ba9b54dfdbf86ac7cd54bf017f5c2a9608616fb02a2a1d65cd6c88f0f6182430edab67efec6b8a0c70bf074758e465d27183437c060d787ec55f9494c930863a8bf003aa40d9bbf04de4d9386c396913fa1996ed78be4abe78cb92ed481094f17c0bff21a5368688036edf794ebef1bd4aa825838a476d8dab5b19959f81a090150f975182109089934575cf1be3112e80d2886f0074aba3e9cfaec4669ff7eb6b093cc128bb11311470e86896c8e528ae7ff142a2930ad305f62b77fb073fbc219c172166eb8b69b8872f123e9a7c8028846f02e42063b9006637b55d6b7e078b6102b5d3fd42447a9d1948faa56444988a57a3222b03846ada687f53389dc474c1977bcd797824c6528bd14808ff50ffb8dae8674e91dcbbb006f39e9bb13e97a5291f16c2612178a60760487a069b9bb52a2696f9726bcb71996666c59c97144a7861b511f01d307948a9f112cd93b17c2dfef6de67f19a54d9191abf6010cc71a00f865002e63ee6b4381cb27f6617e2a4778146def08202ebbac73ee432b08801285c");
        lightParam.put("url_route", "device_switch");
        lightParam.put("device_id", "1");
        lightParam.put("device_status", "0");
        String lightUrl = "https://www.wetoband.com/tre/runTool4ward";
        String lightRes = "";
        for (int i = 0; i <= 20; i++) {
            lightParam.put("device_status", new Integer(i % 2).toString());
            lightParam.put("device_id", new Integer(2).toString());
            lightRes = doPostWithAccessToken(lightUrl, accessToken, lightParam);
//            System.out.println("lightRes:"+lightRes );
            return res;
        }
        return res;
    }
}